﻿package mortal.game.view.tools
{
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import flash.geom.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.mvc.core.*;

    public class FlyEntityController extends Controller
    {
        private var _lastCustomPoint:Point;

        public function FlyEntityController()
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            super.initServer();
            Dispatcher.addEventListener(EventName.FlyItemToPack, this.flyItemToPackHandler);
            Dispatcher.addEventListener(EventName.FlyItemToAnyPoint, this.flyItemToAnyPointHandler);
            return;
        }// end function

        private function flyItemToAnyPointHandler(event:DataEvent) : void
        {
            var sp:Point;
            var ep:Point;
            var scalex:Number;
            var scaley:Number;
            var callBack:Function;
            var shakeIcon:String;
            var onToAnyPointItemLoaded:Function;
            var onLoadIconFailed:Function;
            var itemData:ItemData;
            var e:* = event;
            onToAnyPointItemLoaded = function (param1:ImageInfo) : void
            {
                FlyToNavbarTool.flyToAnyPoint(param1.bitmapData, sp, ep, callBack, 0, 0, false, scalex, scaley, true, shakeIcon);
                return;
            }// end function
            ;
            onLoadIconFailed = function () : void
            {
                MsgManager.showRollTipsMsg("加载图标出错");
                return;
            }// end function
            ;
            var url:String;
            if (e.data[0] is String)
            {
                url = e.data[0] as String;
            }
            else
            {
                itemData = e.data[0] as ItemData;
                url = itemData.itemInfo.icon + ".jpg";
            }
            sp = e.data[1] as Point;
            ep = e.data[2] as Point;
            scalex;
            scaley;
            shakeIcon = ModuleType.Pack;
            if (e.data.length > 3)
            {
                scalex = e.data[3];
            }
            if (e.data.length > 4)
            {
                scaley = e.data[4];
            }
            if (e.data.length > 5)
            {
                callBack = e.data[5];
            }
            if (e.data.length > 6)
            {
                shakeIcon = e.data[6];
            }
            LoaderManager.instance.load(url, onToAnyPointItemLoaded, 3, null, null, onLoadIconFailed);
            return;
        }// end function

        private function flyItemToPackHandler(event:DataEvent) : void
        {
            var _loc_3:String = null;
            var _loc_2:* = event.data as ItemData;
            _loc_3 = _loc_2.itemInfo.icon + ".jpg";
            LoaderManager.instance.load(_loc_3, this.onLoaded);
            return;
        }// end function

        private function onLoaded(param1:ImageInfo) : void
        {
            if (this._lastCustomPoint == null)
            {
                this._lastCustomPoint = new Point(RolePlayer.instance.stagePointX, RolePlayer.instance.stagePointY);
            }
            FlyToNavbarTool.flyToBackPack(param1.bitmapData, this._lastCustomPoint);
            this._lastCustomPoint = null;
            return;
        }// end function

    }
}
